/**
 * 配置全局变量
 */
import { version } from '../../package.json';
export const toRegexStr = (_: any[]) => _.join('|');
export const COLORS = 'colors';
export const ROOT = 'root';
export const GENERATE = 'generate';
export const UNIT = 'unit';
export const IMPORTANT = 'important';
export const GLOB_REG = 'globReg';
export const V_TO_ANY = 'vToAny';
export const BEFORE_CONTENTS = 'beforeContent';
export const AFTER_CONTENT = 'afterContent';
export const EXT_NAME = 'extName';
export const OVERRIDE_RULES = 'overrideRules';
export const MEDIA_QUERIES = 'mediaQueries';
export const CONFIG_FILE_NAME = '.autocss.config.js';

/**
 * 配置全局枚举
 */
// 对应css中的'display'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/display
export const DISPLAY_ENUM = ['unset', 'revert', 'initial', 'list-item', 'table-row', 'table', 'contents', 'none', 'flow-root', 'inline-grid', 'grid', 'inline-flex', 'flex', 'inline-block', 'inline', 'block'];

// 对应css中的'justify-content'属性，参见：https://developer.mozilla.org/en-US/docs/Web/CSS/justify-content
export const JUSTIFY_CONTENT_ENUM = ['center', 'start', 'end', 'flex-start', 'flex-end', 'left', 'right', 'space-between', 'between', 'space-around', 'around', 'space-evenly', 'evenly', 'stretch', 'inherit', 'unset', 'normal'];

// 对应css中的'align-items'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-items
export const ALIGN_ITEMS_ENUM = ['normal', 'stretch', 'center', 'start', 'end', 'flex-start', 'flex-end', 'self-start', 'self-end', 'baseline', 'inherit', 'initial', 'unset'];

// 对应css中的'cursor'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/cursor
export const CURSOR_ENUM = ['auto', 'default', 'none', 'context-menu', 'help', 'pointer', 'progress', 'wait', 'cell', 'crossshair', 'text', 'vertical-text', 'alias', 'copy', 'move', 'no-drop', 'not-allowed', 'grab', 'grabbing', 'all-scroll', 'col-resize', 'row-resize', 'n-resize', 'e-resize', 's-resize', 'w-resize', 'ne-resize', 'nw-resize', 'se-resize', 'sw-resize', 'ew-resize', 'ns-resize', 'nesw-resize', 'nwse-resize', 'zoom-in', 'zoom-out'];

// 对应css中的'length'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/length
export const UNIT_ENUM = ['cap', 'ch', 'em', 'ex', 'ic', 'lh', 'rem', 'rlh', 'vh', 'vw', 'vi', 'vb', 'vmin', 'vmax', 'px', 'cm', 'mm', 'Q', 'in', 'pc', 'pt', 'rpx'];

const PSEUDO_ENUM = ['active', 'any-link', 'blank', 'checked', 'current', 'default', 'defined', 'disabled', 'drop', 'empty', 'enabled', 'first', 'first-child', 'first-of-type', 'fullscreen', 'future', 'focus', 'focus-visible', 'focus-within', 'host', 'hover', 'indeterminate', 'in-range', 'invalid', 'last-child', 'last-of-type', 'left', 'link', 'local-link', 'only-child', 'only-of-type', 'optional', 'out-of-range', 'past', 'placeholder-shown', 'read-only', 'read-write', 'required', 'right', 'root', 'scope', 'target', 'target-within', 'user-invalid', 'valid', 'visited']

// 对应css中的'gap'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/gap
export const GAP_ENUM = ['inherit', 'initial', 'revert', 'revert-layer', 'unset'];

// 对应css中的'vertical-align'属性，参见：https://developer.mozilla.org/zh-CN/docs/Web/CSS/vertical-align
export const VERTICAL_ALIGN_ENUM = ['baseline', 'sub', 'super', 'text-top', 'text-bottom', 'middle', 'top', 'bottom', 'inherit', 'initial', 'unset'];

export const DISPLAY_STR = toRegexStr(DISPLAY_ENUM);
export const PSEUDO_STR = toRegexStr(PSEUDO_ENUM);
export const JUSTIFY_CONTENT_STR = toRegexStr(JUSTIFY_CONTENT_ENUM);
export const ALIGN_ITEMS_STR = toRegexStr(ALIGN_ITEMS_ENUM);
export const CURSOR_STR = toRegexStr(CURSOR_ENUM);
export const UNIT_STR = toRegexStr(UNIT_ENUM);
export const VERTICAL_ALIGN_STR = toRegexStr(VERTICAL_ALIGN_ENUM);
export const GAP_STR = toRegexStr(GAP_ENUM);

// 输出的css文件头部内容
export let CSS_ANNOTATION = '';
CSS_ANNOTATION += '@charset "UTF-8";\n';
CSS_ANNOTATION += '/* https://gitee.com/bad_-code/vite-plugin-autocss/\n';
CSS_ANNOTATION += `  version: v${version}\n`;
CSS_ANNOTATION += '  该文件将会自动初始化并更新，切勿直接修改！\n';
CSS_ANNOTATION += '*/\n\n';

// 媒体查询
export const BASE_MEDIA_QUERY = {
    sm: '(min-width: 640px)',
    md: '(min-width: 768px)',
    lg: '(min-width: 1024px)',
    xl: '(min-width: 1280px)'
};

export const BASE_MEDIA_QUERY_KEY = Object.keys(BASE_MEDIA_QUERY);

// 定义class中的数字变体正则
export const NONNEGATIVE_NUMBER_REGEX_STR = '(0|([1-9]\\d*))(\\.\\d*[1-9])?';

// 定义class中的方向基础变体映射关系
export const DIRECTION_MAP = new Map();
DIRECTION_MAP.set(undefined, ['']);
DIRECTION_MAP.set('x', ['left', 'right']);
DIRECTION_MAP.set('y', ['top', 'bottom']);
DIRECTION_MAP.set('t', ['top']);
DIRECTION_MAP.set('b', ['bottom']);
DIRECTION_MAP.set('l', ['left']);
DIRECTION_MAP.set('r', ['right']);
DIRECTION_MAP.set('top', ['top']);
DIRECTION_MAP.set('bottom', ['bottom']);
DIRECTION_MAP.set('left', ['left']);
DIRECTION_MAP.set('right', ['right']);